// pages/index/public/custom/cucity.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchLetter: ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"],
    showLetter: "",
    winHeight: 0,
    isShowLetter: false,
    scrollTop: 0, //置顶高度
    scrollTopId: '', //置顶id
    city: '厦门'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var searchLetter = that.data.searchLetter;
    var sysInfo = wx.getSystemInfoSync();
    var winHeight = sysInfo.windowHeight;
    var itemH = winHeight / searchLetter.length;
    wx.request({
      url: app.apiUrl('c=zhaobiao/index&a=view_estimate'),
      data: {},
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "GET",
      success: function(res) {
        console.log(res.data)
        var polist = res.data.datas.province_list
        that.setData({
          citys: polist
        })
      },
      fail: function(res) {
        console.log('请求失败', res.data)
      }
    })
    that.setData({
      winHeight: winHeight,
      itemH: itemH,
    })
  },
  onShow: function(e) {
    var that = this
   

  },
  //直辖市选择
  directcity: function(e) {
    var that = this
    var city = e.currentTarget.dataset.city;
    var cityid = e.currentTarget.dataset.child
    var childlength = e.currentTarget.dataset.theid
    if (childlength ==0){
      var pages = getCurrentPages();
      var currPage = pages[pages.length - 1]; //当前页面
      var prevPage = pages[pages.length - 2]; //上一个页面
      prevPage.setData({
        city: city,
        cityid: 0,
        proviceid: cityid
      })
      wx.navigateBack();
    }
  
  },

  clickLetter: function(e) {
    var that = this
    var p = 750 / that.data.winWidth;
    var citys = that.data.citys
    //console.log(e.currentTarget.dataset.letter)
    var showLetter = e.currentTarget.dataset.letter;
    //console.log(citys)
    this.setData({
      showLetter: showLetter,
      isShowLetter: true,
      scrollTopId: showLetter,
    })
    var that = this;
    setTimeout(function() {
      that.setData({
        isShowLetter: false
      })
    }, 1000)

  },
  //当前城市选择
  choosenow: function(e) {
    var that = this
    var city = e.currentTarget.dataset.city;
    var cityid = e.currentTarget.dataset.child
    var proviceid = e.currentTarget.dataset.parentid
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    var prevPage = pages[pages.length - 2]; //上一个页面

    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      city: city,
      cityid: cityid,
      proviceid: proviceid
    })
    wx.navigateBack();
  },
  bindCity: function(e) {
    var that = this
    var city = e.currentTarget.dataset.city; //把本页面需要传递的参数保存在本地缓存里
    var cityid = e.currentTarget.dataset.child
    var proviceid = e.currentTarget.dataset.parentid
    console.log(cityid)
    that.setData({
      city: city
    })
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    var prevPage = pages[pages.length - 2]; //上一个页面

    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      city: city,
      cityid: cityid,
      proviceid: proviceid
    })

    wx.navigateBack();
    console.log(e)
  },
  onReady: function() {

  }


})